<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>&lt;GMainContext&gt;: </title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.2">
<link rel="home" href="index.html" title="">
<link rel="up" href="ch01.html" title="GLib">
<link rel="prev" href="re32.html" title="&lt;%GLibLogWriterOutput&gt;">
<link rel="next" href="re34.html" title="&lt;GMainLoop&gt;">
<meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
<td><a accesskey="p" href="re32.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="re34.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="id-1.1.34"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2>&lt;GMainContext&gt;</h2>
<p>&lt;GMainContext&gt;</p>
</div>
<div class="refsect1">
<a name="id-1.1.34.2"></a><h2>Description</h2>
<p>The <code class="code">GMainContext</code> struct is an opaque data
type representing a set of sources to be handled in a main loop.</p>
</div>
<div class="refsect1">
<a name="id-1.1.34.3"></a><h2>Functions</h2>
<div class="refsect2">
<a name="id-1.1.34.3.2"></a><h3>acquire?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:acquire? self))
</pre></div>
<p>Tries to become the owner of the specified context.
If some other thread is the owner of the context,
returns <code class="constant">FALSE</code> immediately. Ownership is properly
recursive: the owner can require ownership again
and will release ownership when <code class="function">g_main_context_release()</code>
is called as many times as <code class="function">g_main_context_acquire()</code>.
</p>
<p>You must be the owner of a context before you
can call <code class="function">g_main_context_prepare()</code>, <code class="function">g_main_context_query()</code>,
<code class="function">g_main_context_check()</code>, <code class="function">g_main_context_dispatch()</code>.</p>
<div class="refsect3">
<a name="id-1.1.34.3.2.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.3"></a><h3>add-poll</h3>
<div class="informalexample"><pre class="programlisting">(define-values () (main-context:add-poll self fd priority))
</pre></div>
<p>Adds a file descriptor to the set of file descriptors polled for
this context. This will very seldom be used directly. Instead
a typical event source will use <code class="function">g_source_add_unix_fd()</code> instead.</p>
<div class="refsect3">
<a name="id-1.1.34.3.3.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span> (or <code class="constant">NULL</code> for the default context)</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>fd</p></td>
<td class="parameter_description">
<p>a <span class="type">GPollFD</span> structure holding information about a file
     descriptor to watch.</p>
<p>Passed as <code class="code">fd</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>priority</p></td>
<td class="parameter_description">
<p>the priority for this file descriptor which should be
     the same as the priority used for <code class="function">g_source_attach()</code> to ensure that the
     file descriptor is polled whenever the results may be needed.</p>
<p>Passed as <code class="code">priority</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.4"></a><h3>check?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:check? self max-priority fds))
</pre></div>
<p>Passes the results of polling back to the main loop.
</p>
<p>You must have successfully acquired the context with
<code class="function">g_main_context_acquire()</code> before you may call this function.</p>
<div class="refsect3">
<a name="id-1.1.34.3.4.5"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>max_priority</p></td>
<td class="parameter_description">
<p>the maximum numerical priority of sources to check</p>
<p>Passed as <code class="code">max-priority</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>fds</p></td>
<td class="parameter_description">
<p>array of <span class="type">GPollFD</span>'s that was passed to
      the last call to <code class="function">g_main_context_query()</code></p>
<p>Passed as <code class="code">fds</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>n_fds</p></td>
<td class="parameter_description">
<p>return value of <code class="function">g_main_context_query()</code></p>
<p>Inferred from <code class="code">fds</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.5"></a><h3>dispatch</h3>
<div class="informalexample"><pre class="programlisting">(define-values () (main-context:dispatch self))
</pre></div>
<p>Dispatches all pending sources.
</p>
<p>You must have successfully acquired the context with
<code class="function">g_main_context_acquire()</code> before you may call this function.</p>
<div class="refsect3">
<a name="id-1.1.34.3.5.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.6"></a><h3>find-source-by-id</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:find-source-by-id self source-id))
</pre></div>
<p>Finds a <span class="type">GSource</span> given a pair of context and ID.
</p>
<p>It is a programmer error to attempt to look up a non-existent source.
</p>
<p>More specifically: source IDs can be reissued after a source has been
destroyed and therefore it is never valid to use this function with a
source ID which may have already been removed.  An example is when
scheduling an idle to run in another thread with <code class="function">g_idle_add()</code>: the
idle may already have run and been removed by the time this function
is called on its (now invalid) source ID.  This source ID may have
been reissued, leading to the operation being performed against the
wrong source.</p>
<div class="refsect3">
<a name="id-1.1.34.3.6.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span> (if <code class="constant">NULL</code>, the default context will be used)</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>source_id</p></td>
<td class="parameter_description">
<p>the source ID, as returned by <code class="function">g_source_get_id()</code>.</p>
<p>Passed as <code class="code">source-id</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.7"></a><h3>find-source-by-user-data</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return)
  (main-context:find-source-by-user-data self user-data))
</pre></div>
<p>Finds a source with the given user data for the callback.  If
multiple sources exist with the same user data, the first
one found will be returned.</p>
<div class="refsect3">
<a name="id-1.1.34.3.7.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>user_data</p></td>
<td class="parameter_description">
<p>the user_data for the callback.</p>
<p>Passed as <code class="code">user-data</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.8"></a><h3>invoke-full</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  ()
  (main-context:invoke-full self priority function data notify))
</pre></div>
<p>Invokes a function in such a way that <em class="parameter"><code>context</code></em> is owned during the
invocation of <em class="parameter"><code>function</code></em>.
</p>
<p>This function is the same as <code class="function">g_main_context_invoke()</code> except that it
lets you specify the priority in case <em class="parameter"><code>function</code></em> ends up being
scheduled as an idle and also lets you give a <span class="type">GDestroyNotify</span> for <em class="parameter"><code>data</code></em>.
</p>
<p><em class="parameter"><code>notify</code></em> should not assume that it is called from any particular
thread or with any particular context acquired.</p>
<div class="refsect3">
<a name="id-1.1.34.3.8.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span>, or <code class="constant">NULL</code></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>priority</p></td>
<td class="parameter_description">
<p>the priority at which to run <em class="parameter"><code>function</code></em></p>
<p>Passed as <code class="code">priority</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>function</p></td>
<td class="parameter_description">
<p>function to call</p>
<p>Passed as <code class="code">function</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>data</p></td>
<td class="parameter_description">
<p>data to pass to <em class="parameter"><code>function</code></em></p>
<p>Passed as <code class="code">data</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>notify</p></td>
<td class="parameter_description">
<p>a function to call when <em class="parameter"><code>data</code></em> is no longer in use, or <code class="constant">NULL</code>.</p>
<p>Passed as <code class="code">notify</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.9"></a><h3>is-owner?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:is-owner? self))
</pre></div>
<p>Determines whether this thread holds the (recursive)
ownership of this <span class="type">GMainContext</span>. This is useful to
know before waiting on another thread that may be
blocking to get ownership of <em class="parameter"><code>context</code></em>.</p>
<div class="refsect3">
<a name="id-1.1.34.3.9.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.10"></a><h3>iteration?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:iteration? self may-block))
</pre></div>
<p>Runs a single iteration for the given main loop. This involves
checking to see if any event sources are ready to be processed,
then if no events sources are ready and <em class="parameter"><code>may_block</code></em> is <code class="constant">TRUE</code>, waiting
for a source to become ready, then dispatching the highest priority
events sources that are ready. Otherwise, if <em class="parameter"><code>may_block</code></em> is <code class="constant">FALSE</code>
sources are not waited to become ready, only those highest priority
events sources will be dispatched (if any), that are ready at this
given moment without further waiting.
</p>
<p>Note that even when <em class="parameter"><code>may_block</code></em> is <code class="constant">TRUE</code>, it is still possible for
<code class="function">g_main_context_iteration()</code> to return <code class="constant">FALSE</code>, since the wait may
be interrupted for other reasons than an event source becoming ready.</p>
<div class="refsect3">
<a name="id-1.1.34.3.10.5"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span> (if <code class="constant">NULL</code>, the default context will be used)</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>may_block</p></td>
<td class="parameter_description">
<p>whether the call may block.</p>
<p>Passed as <code class="code">may-block</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.11"></a><h3>pending?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:pending? self))
</pre></div>
<p>Checks if any sources have pending events for the given context.</p>
<div class="refsect3">
<a name="id-1.1.34.3.11.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span> (if <code class="constant">NULL</code>, the default context will be used)</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.12"></a><h3>pop-thread-default</h3>
<div class="informalexample"><pre class="programlisting">(define-values () (main-context:pop-thread-default self))
</pre></div>
<p>Pops <em class="parameter"><code>context</code></em> off the thread-default context stack (verifying that
it was on the top of the stack).</p>
<div class="refsect3">
<a name="id-1.1.34.3.12.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span> object, or <code class="constant">NULL</code></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.13"></a><h3>prepare</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return priority) (main-context:prepare self))
</pre></div>
<p>Prepares to poll sources within a main loop. The resulting information
for polling is determined by calling g_main_context_query ().
</p>
<p>You must have successfully acquired the context with
<code class="function">g_main_context_acquire()</code> before you may call this function.</p>
<div class="refsect3">
<a name="id-1.1.34.3.13.5"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>priority</p></td>
<td class="parameter_description">
<p>location to store priority of highest priority
           source already ready.</p>
<p>Passed as <code class="code">priority</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.14"></a><h3>push-thread-default</h3>
<div class="informalexample"><pre class="programlisting">(define-values () (main-context:push-thread-default self))
</pre></div>
<p>Acquires <em class="parameter"><code>context</code></em> and sets it as the thread-default context for the
current thread. This will cause certain asynchronous operations
(such as most [gio][gio]-based I/O) which are
started in this thread to run under <em class="parameter"><code>context</code></em> and deliver their
results to its main loop, rather than running under the global
default context in the main thread. Note that calling this function
changes the context returned by <code class="function">g_main_context_get_thread_default()</code>,
not the one returned by <code class="function">g_main_context_default()</code>, so it does not affect
the context used by functions like <code class="function">g_idle_add()</code>.
</p>
<p>Normally you would call this function shortly after creating a new
thread, passing it a <span class="type">GMainContext</span> which will be run by a
<span class="type">GMainLoop</span> in that thread, to set a new default context for all
async operations in that thread. In this case you may not need to
ever call <code class="function">g_main_context_pop_thread_default()</code>, assuming you want the
new <span class="type">GMainContext</span> to be the default for the whole lifecycle of the
thread.
</p>
<p>If you don't have control over how the new thread was created (e.g.
in the new thread isn't newly created, or if the thread life
cycle is managed by a <span class="type">GThreadPool</span>), it is always suggested to wrap
the logic that needs to use the new <span class="type">GMainContext</span> inside a
<code class="function">g_main_context_push_thread_default()</code> / <code class="function">g_main_context_pop_thread_default()</code>
pair, otherwise threads that are re-used will end up never explicitly
releasing the <span class="type">GMainContext</span> reference they hold.
</p>
<p>In some cases you may want to schedule a single operation in a
non-default context, or temporarily use a non-default context in
the main thread. In that case, you can wrap the call to the
asynchronous operation inside a
<code class="function">g_main_context_push_thread_default()</code> /
<code class="function">g_main_context_pop_thread_default()</code> pair, but it is up to you to
ensure that no other asynchronous operations accidentally get
started while the non-default context is active.
</p>
<p>Beware that libraries that predate this function may not correctly
handle being used from a thread with a thread-default context. Eg,
see <code class="function">g_file_supports_thread_contexts()</code>.</p>
<div class="refsect3">
<a name="id-1.1.34.3.14.8"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span>, or <code class="constant">NULL</code> for the global default context</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.15"></a><h3>query!</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return timeout- fds)
  (main-context:query! self max-priority fds))
</pre></div>
<p>Determines information necessary to poll this main loop.
</p>
<p>You must have successfully acquired the context with
<code class="function">g_main_context_acquire()</code> before you may call this function.</p>
<div class="refsect3">
<a name="id-1.1.34.3.15.5"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>max_priority</p></td>
<td class="parameter_description">
<p>maximum priority source to check</p>
<p>Passed as <code class="code">max-priority</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>timeout_</p></td>
<td class="parameter_description">
<p>location to store timeout to be used in polling</p>
<p>Passed as <code class="code">timeout-</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>fds</p></td>
<td class="parameter_description">
<p>location to
      store <span class="type">GPollFD</span> records that need to be polled.</p>
<p>Passed as <code class="code">fds</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>n_fds</p></td>
<td class="parameter_description">
<p>length of <em class="parameter"><code>fds</code></em>.</p>
<p>Inferred from <code class="code">fds</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.16"></a><h3>ref</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:ref self))
</pre></div>
<p>Increases the reference count on a <span class="type">GMainContext</span> object by one.</p>
<div class="refsect3">
<a name="id-1.1.34.3.16.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.17"></a><h3>release</h3>
<div class="informalexample"><pre class="programlisting">(define-values () (main-context:release self))
</pre></div>
<p>Releases ownership of a context previously acquired by this thread
with <code class="function">g_main_context_acquire()</code>. If the context was acquired multiple
times, the ownership will be released only when <code class="function">g_main_context_release()</code>
is called as many times as it was acquired.</p>
<div class="refsect3">
<a name="id-1.1.34.3.17.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.18"></a><h3>remove-poll</h3>
<div class="informalexample"><pre class="programlisting">(define-values () (main-context:remove-poll self fd))
</pre></div>
<p>Removes file descriptor from the set of file descriptors to be
polled for a particular context.</p>
<div class="refsect3">
<a name="id-1.1.34.3.18.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>fd</p></td>
<td class="parameter_description">
<p>a <span class="type">GPollFD</span> descriptor previously added with <code class="function">g_main_context_add_poll()</code></p>
<p>Passed as <code class="code">fd</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.19"></a><h3>unref</h3>
<div class="informalexample"><pre class="programlisting">(define-values () (main-context:unref self))
</pre></div>
<p>Decreases the reference count on a <span class="type">GMainContext</span> object by one. If
the result is zero, free the context and free all associated memory.</p>
<div class="refsect3">
<a name="id-1.1.34.3.19.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.20"></a><h3>wakeup</h3>
<div class="informalexample"><pre class="programlisting">(define-values () (main-context:wakeup self))
</pre></div>
<p>If <em class="parameter"><code>context</code></em> is currently blocking in <code class="function">g_main_context_iteration()</code>
waiting for a source to become ready, cause it to stop blocking
and return.  Otherwise, cause the next invocation of
<code class="function">g_main_context_iteration()</code> to return without blocking.
</p>
<p>This API is useful for low-level control over <span class="type">GMainContext</span>; for
example, integrating it with main loop implementations such as
<span class="type">GMainLoop</span>.
</p>
<p>Another related use for this function is when implementing a main
loop with a termination condition, computed from multiple threads:
</p>
<div class="informalexample"><pre class="programlisting">
  #define NUM_TASKS 10
  static volatile gint tasks_remaining = NUM_TASKS;
  ...
 
  while (g_atomic_int_get (&amp;tasks_remaining) != 0)
    g_main_context_iteration (NULL, TRUE);
</pre></div>
 
<p>Then in a thread:
</p>
<div class="informalexample"><pre class="programlisting">
  perform_work();

  if (g_atomic_int_dec_and_test (&amp;tasks_remaining))
    g_main_context_wakeup (NULL);
</pre></div>
<div class="refsect3">
<a name="id-1.1.34.3.20.8"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description">
<p>a <span class="type">GMainContext</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.21"></a><h3>main-context:new</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:new))
</pre></div>
<p>Undocumented</p>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.22"></a><h3>main-context:default</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:default))
</pre></div>
<p>Returns the global default main context. This is the main context
used for main loop functions when a main loop is not explicitly
specified, and corresponds to the "main" main loop. See also
<code class="function">g_main_context_get_thread_default()</code>.</p>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.23"></a><h3>main-context:get-thread-default</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:get-thread-default))
</pre></div>
<p>Gets the thread-default <span class="type">GMainContext</span> for this thread. Asynchronous
operations that want to be able to be run in contexts other than
the default one should call this method or
<code class="function">g_main_context_ref_thread_default()</code> to get a <span class="type">GMainContext</span> to add
their <span class="type">GSources</span> to. (Note that even in single-threaded
programs applications may sometimes want to temporarily push a
non-default context, so it is not safe to assume that this will
always return <code class="constant">NULL</code> if you are running in the default thread.)
</p>
<p>If you need to hold a reference on the context, use
<code class="function">g_main_context_ref_thread_default()</code> instead.</p>
</div>
<div class="refsect2">
<a name="id-1.1.34.3.24"></a><h3>main-context:ref-thread-default</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:ref-thread-default))
</pre></div>
<p>Gets the thread-default <span class="type">GMainContext</span> for this thread, as with
<code class="function">g_main_context_get_thread_default()</code>, but also adds a reference to
it with <code class="function">g_main_context_ref()</code>. In addition, unlike
<code class="function">g_main_context_get_thread_default()</code>, if the thread-default context
is the global default context, this will return that <span class="type">GMainContext</span>
(with a ref added to it) rather than returning <code class="constant">NULL</code>.</p>
</div>
</div>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.33.1</div>
</body>
</html>
